<?php

/* ========================================================================= */
/* This file is part of the HypnoPHP Framework Library                       */
/* Copyright (c) 2009-2010, Radu Buzea                                       */
/* ========================================================================= */

/*
 @author Radu Buzea
 @copyright Copyright (c) 2009-2010, Radu Buzea (www.hypnosis.ro)
 @license GNU Lesser General Public License (www.gnu.org/copyleft/lesser.html)
*/

// ============================================================================
// Class: Helper_Header
// ============================================================================

class Helper_Header extends HBaseHelper
{

	public function run()
	{
		$this->title = '';
		$this->content_type = 'text/html; charset=utf-8';
	}

	public function set_title($title = '')
	{
		$this->title = trim($title);
	}

	public function add_javascript($js_uri = '')
	{
		$js_uri = trim($js_uri);
		if ($js_uri != '') {
			if (!isset($this->javascripts) || !is_array($this->javascripts)) {
				$this->javascripts = array();
			}
			if (!in_array($js_uri, $this->javascripts)) {
				return array_push($this->javascripts, $js_uri);
			}
		}
		return false;
	}

	public function add_stylesheet($css_uri = '')
	{
		$css_uri = trim($css_uri);
		if ($css_uri != '') {
			if (!isset($this->stylesheets) || !is_array($this->stylesheets)) {
				$this->stylesheets = array();
			}
			if (!in_array($js_uri, $this->stylesheets)) {
				return array_push($this->stylesheets, $css_uri);
			}
		}
		return false;
	}

	public function output()
	{
		$code = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . PHP_EOL .
			'<html xmlns="http://www.w3.org/1999/xhtml">' . PHP_EOL . '<head>' . PHP_EOL .
			'	<title>' . $this->title . '</title>' . PHP_EOL .
			'	<meta http-equiv="content-type" content="' . $this->content_type . '" />' . PHP_EOL .
			'</head>' . PHP_EOL;
		return $code;
	}

}